"""
import shutil
shutil.rmtree("log.txt")
"""
"""
import os
files = ['log.txt','chaindata/']
for my_file in files:
    if os.path.exists(my_file):
        #删除文件，可使用以下两种方法。
        os.remove(my_file)
        #os.unlink(my_file)
    else:
        print ('no such file:%s'%my_file)
"""

import os
import shutil
paths = ["logfile","logfile"]
paths1=['chaindata']
exclude=['chaindata/chainstate','chaindata/index']+paths1


def del_file(path):
      for i in os.listdir(path):
         path_file = os.path.join(path,i)  
         if os.path.isfile(path_file):
             os.remove(path_file)
         else:
            del_file(path_file)


def del_file1(path):
      for i in os.listdir(path):
         path_file = os.path.join(path,i)  
         if os.path.isfile(path_file):
             os.remove(path_file)
         else:
                if path_file in exclude:
                    del_file1(path_file)
                else:
                    shutil.rmtree(path_file)
for path in paths:
    del_file(path)
for path in paths1:
    del_file1(path)


            


